<template>
  <div class="dingxin">
    <el-form ref="addForm" :model="form" :rules="rules" label-width="120px" style="width: 480px;">
      <el-form-item label="当前基本工资" prop="currentBasicSalary">
        <el-input v-model="form.currentBasicSalary" placeholder="当前基本工资" />
      </el-form-item>
      <el-form-item label="当前岗位工资" prop="currentPostWage">
        <el-input v-model="form.currentPostWage" placeholder="当前岗位工资" />
      </el-form-item>
      <el-form-item label="当前工资合计">
        <el-input :value="currentTotal" disabled />
      </el-form-item>
      <el-form-item label="转正基本工资" prop="correctionOfBasicWages">
        <el-input v-model="form.correctionOfBasicWages" placeholder="转正基本工资" />
      </el-form-item>
      <el-form-item label="转正岗位工资" prop="turnToPostWages">
        <el-input v-model="form.turnToPostWages" placeholder="转正岗位工资" />
      </el-form-item>
      <el-form-item label="转正工资合计">
        <el-input :value="correctionTotal" disabled />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="btnOK">确认</el-button>
        <el-button @click="btnCancel">关闭</el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import { salarysInit } from '@/api/salarys'
export default {
  name: 'Dingxin',
  props: {
    userid: {
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      form: {
        currentBasicSalary: '', // 当前基本工资
        currentPostWage: '', // 当前岗位工资
        correctionOfBasicWages: '', // 转正基本工资
        turnToPostWages: '' // 转正岗位工资
      },
      rules: {
        currentBasicSalary: [{ required: true, message: '请输入当前基本工资', trigger: 'blur' }], // 当前基本工资
        currentPostWage: [{ required: true, message: '请输入当前基本工资', trigger: 'blur' }], // 当前岗位工资
        correctionOfBasicWages: [{ required: true, message: '请输入当前基本工资', trigger: 'blur' }], // 转正基本工资
        turnToPostWages: [{ required: true, message: '请输入当前基本工资', trigger: 'blur' }] // 转正岗位工资
      }
    }
  },
  computed: {
    currentTotal() {
      return Number(this.form.currentBasicSalary) + Number(this.form.currentPostWage)
    },
    correctionTotal() {
      return Number(this.form.correctionOfBasicWages) + Number(this.form.turnToPostWages)
    }
  },
  methods: {
    async btnOK() {
      //   this.$emit('btnOK', this.form)
      try {
        await salarysInit({ ...this.form, userId: this.userid })
        this.$message.success('设置成功')
        this.btnCancel()
        // console.log(res)
      } catch (err) {
        // console.log(err.response.data.message)
        this.$message.error(err.response.data.message)
      }
    },
    btnCancel() {
      this.$refs.addForm.resetFields()
      this.$emit('closeDialog', false)
    }
  }
}
</script>

<style>
</style>
